package br.com.Orange.view.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.Orange.negocio.Fachada;
import br.com.Orange.negocio.funcionario.model.Funcionario;
import br.com.Orange.view.form.LoginForm;

public class LoginAction extends Action {

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		HttpSession session;
		
		Funcionario funcionario = ((LoginForm)form).getFuncionario();
		Funcionario encontrado = Fachada.obterInstancia().procurarFuncionario(funcionario.getMatricula());
		
		session = request.getSession();
		session.setAttribute("funcionario", encontrado);
		return mapping.findForward("success");
		
	}

	
}
